package com.parknfly.mycalendar.calendar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.parknfly.mycalendar.R;
import com.parknfly.mycalendar.calendar.adapter.MyDateAdapter;

import java.util.Calendar;


public class MyDateView extends RelativeLayout {

    RecyclerView recyclerView;

    public MyDateView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.my_date_view, this, true);
        initUI();
    }

    public MyDateView(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.my_date_view, this, true);
        initUI();
    }

    private void initUI() {
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        MyDateAdapter dateAdapter = new MyDateAdapter();
        recyclerView.setAdapter(dateAdapter);
        dateAdapter.setDateHandler(new MyDateAdapter.DateHandler() {
            @Override
            public void getDate(Calendar b, Calendar e) {
                String timeB = String.valueOf(b.get(Calendar.DAY_OF_MONTH));
                String timeE = String.valueOf(e.get(Calendar.DAY_OF_MONTH));
                Toast.makeText(getContext(), "开始：" + timeB + "   结束：" + timeE, Toast.LENGTH_LONG).show();
            }
        });
    }

}
